//import Myhead from 'components/head/head.vue'
//import Top from 'components/top/top.vue'
//import Search from 'components/search/search.vue'
//import Foot from 'components/foot/foot.vue'




import Vue from 'vue'

import {
  AlertPlugin,
  ToastPlugin,
  ConfirmPlugin,
  Actionsheet,
  XDialog
} from 'vux'


Vue.use(ToastPlugin,{time:3000});

import {
  TransferDomDirective as TransferDom
} from 'vux'


import {
  Qrcode
} from 'vux'
import qs from 'qs'


import {
  Alert
} from '../../../node_modules/element-ui';

import Bus from '@/common/js/bus.js'



import {
  isIdNumber,
  dateStringToDateTime,
  timeFormat,
  startTime,
  setTitle,
  formatCity,
  toDecimal2
} from "@/common/js/main.js";



//Vue.use(AlertPlugin)

var mixin = {
  components: {
    Actionsheet,
    XDialog,
    Qrcode
  },
  directives: {
    TransferDom
  },
  data() {
    return {
      showMenu: false,
      pageType: '',
      menus: {
        menu1: '立即报名',
        menu2: '我的报名',
        menu3: '成绩查询',
        menu4: '活动官网',
        menu5: '客服电话'
      },
      href: '',
      tel: '',
      raceInfo: {},
      raceInfoList: []




    };
  },
  created: function () {
    if (!!window.pageConfig.raceid && window.localStorage.pageType === 'baoming') {
      window.localStorage.setItem('raceId', window.pageConfig.raceid)
    }


    //if(this.$router.)





    this._getRaceinfo1()
    if (typeof wx !== 'undefined')
      wx.miniProgram.postMessage({
        data: {
          returnUrl: window.location.href
        }
      });

    //兼容移动端安卓inout被遮挡的问题

    var screenHeight = document.body.offsetHeight
    if (/Android [4-6]/.test(navigator.appVersion)) {
      window.addEventListener("resize", function () {
        if (
          document.activeElement.tagName == "INPUT" ||
          document.activeElement.tagName == "TEXTAREA"
        ) {



          var nowHeight = document.body.offsetHeight



          // if (!!document.hasFocus()) {

          //   document.querySelector(".weui-tabbar").style.position = "static";
          //return;
          // }
          //console.log('-+')
          //console.log(screenHeight)
          //console.log(nowHeight)
          if (nowHeight < screenHeight) {
            //alert(1)


            //键盘弹出的事件处理
            document.activeElement.scrollIntoViewIfNeeded(true);

            document.querySelector(".fixBottomButton").style.display = "none";
            //document.querySelector(".fixBottomButton").style.position = "fixed";
            //console.log(document.querySelector(".fixBottomButton"))
          } else {


            //键盘收起的事件处理
            document.querySelector(".fixBottomButton").style.display = "block";
            //document.querySelector(".fixBottomButton").style.position = "static";
            //alert("收起");
          }


          //console.log(document.hasFocus() )
          //document.activeElement.scrollIntoView(true);

        }


      });
    }

    this.pageType = window.localStorage.getItem("pageType");




    //window.localStorage.setItem("pageType", "baoming");


  },
  mounted() {

  },
  methods: {
    _getRaceinfo1() {

      this.axios
        .post(
          `${window.host}race/show`,
          qs.stringify({
            raceid: this.page.raceid
          })
        )
        .then(response => {
          if (response.data.code == "200") {
            //赛事信息
            this.raceInfo = response.data.data;

            Bus.$emit('raceInfo', this.raceInfo)
            //console.log('---123---')
            //console.log(JSON.stringify(this.raceInfo))
            window.localStorage.setItem('raceinfo',JSON.stringify(this.raceInfo))



            //console.log(this.raceInfo)
            this.href = this.raceInfo.homepage
            this.tel = this.raceInfo.tel

            //免责声明
            window.localStorage.setItem(
              "disclaimerID",
              this.raceInfo.disclaimer
            );


            //

            //赛事信息
            this.raceInfo = response.data.data;

            //this._getRuleHtml(this.raceInfo.rule);

            if (!!this.raceInfo.time) {
              //处理比赛时间 精确到时分
              this.raceInfoList.push({
                label: "时间",
                value: this.raceInfo.time.split(" ")[0] +
                  " " +
                  this.raceInfo.time.split(" ")[1].split(":")[0] +
                  ":" +
                  this.raceInfo.time.split(" ")[1].split(":")[1]
              });
            }

            if (!!this.raceInfo.address) {
              if (!!this.raceInfo.city) {
                //处理比赛地点
                this.raceInfoList.push({
                  label: "地点",
                  value: formatCity(this.raceInfo.city) + this.raceInfo.address
                });
              } else {
                //处理比赛地点
                this.raceInfoList.push({
                  label: "地点",
                  value: formatCity(this.raceInfo.city)
                });
              }
            }






            //

          }
        });
    },
    menuClick(menuKey, menuItem) {
      switch (menuKey) {
        case 'menu1':
          this.$router.push(
            `/list?race_id=${window.localStorage.getItem("raceId")}`
          );
          break;
        case 'menu2':
          this.$router.push(
            `/query`
          );
          break;
        case 'menu3':
          this.$router.push(
            `/report`
          );
          break;
        case 'menu4':
          //console.log(this.href)
          if (!!this.href) {

            if (this.href.indexOf('http')) {
              window.location.href = 'http://' + this.href
            }

          }
          break;
        case 'menu5':
          console.log(this.tel)
          if (!!this.tel) {
            window.location.href = `tel:${this.tel}`;
          }
          break;

        default:

      }
    }
  }
}
export default mixin
